<?php
namespace app\agent\controller;

use app\common\model\AgentArea;
use app\common\model\AgentManage;
use app\common\model\CashWith;
use app\common\model\Orders;

class Account extends Base
{
    /**
     * 钱包信息
     */
    public function account() {
        $list = CashWith::where('label',3)->order('start_time','desc')->paginate(10,false,[
            'type'     => 'bootstrap',
        ]);
        $info = AgentManage::where('agem_id',$this->agent_manage_id)->find();
        $this->assign('page', $list->render());
        $this->assign('list',$list);//提现记录
        $this->assign('info',$info);
        return $this->fetch();
    }

    /**
     * 提现
     */
    public function withdraw(){
        if($this->request->method() === "POST"){
            $id = $this->request->post('id');
            $account = $this->request->post('account');
            $data['agent_id'] = $id;
            $data['money'] = $account*100;
            $data['c_order'] = date('YmdHis')."DL".mt_rand(00000,99999);
            $data['label'] = 3;
            $data['start_time'] = time();
            $data['c_status'] = -1;
//            $this->
        }
    }

    /**
     * 账户信息
     */
    public function account_info()
    {
        $info = AgentManage::with('getprovince,getcity,getregion')->where('agem_id',$this->agent_manage_id)->find();
        $agea = AgentArea::with('getarea')->where('agea_agent_manage',$info->agem_id)->select();
        $this->assign('agea',$agea);
        $this->assign('info',$info);
        return $this->fetch();
    }

    /**
     * 代理收入列表
     */
    public function account_income(){
        $list = Orders::with('shops')->where('ord_agent',$this->agent_manage_id)->where('ord_status',1)->order('ord_create_time','desc')->paginate(10,false,[
            'type'     => 'bootstrap',
        ]);
        $info = AgentManage::where('agem_id',$this->agent_manage_id)->find();
        $this->assign('page', $list->render());
        $this->assign('list',$list);//提现记录
        $this->assign('info',$info);
        return $this->fetch();
    }


}